/**
 * 抽奖箱
 */
(function(){
	
	function LotteryBox(options){
		this.init(options);
	}
	
	LotteryBox.prototype = {
		init:function(options){
			this.container = options.container;
			
			this.time = options.time || 1; //轮询时间
			this.moveHeight = this.container.find('li:first').outerHeight(true);//每次滚动距离 一个项的高度
			this.bufferTime = options.bufferTime || 2400 ; //开奖缓冲时间 单位(毫秒)
			this.list = this.container.find('li');
			this.height = this.container.height();
			this.size = this.list.length;
			this._clone = this.list.clone();
			this.container.append(this._clone);
			this.index = 0;
		},
		start:function(){
			var _this = this;
			this.timeout = setInterval(function(){
				_this.move();
				_this.index ++;
				_this.index %=  _this.size;
			}, this.time);
		},
		lottery:function(resultIndex){
			clearInterval(this.timeout);
			this.index = resultIndex;
			this.move();
		},
		move:function(){
			var marginTop = this.index * this.moveHeight * -1;
			marginTop %= this.height;
			this.list.removeClass("active");
			this.list.eq(this.index).addClass("active");
			this.container.css("marginTop", marginTop);
		}
	};
	
	window.LotteryBox = LotteryBox;
	
})();